atspi: Derive readonly state from aria properties
authorMatthias Clasen <mclasen@redhat.com>
Mon, 12 Oct 2020 03:35:34 +0000 (23:35 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 12 Oct 2020 19:10:40 +0000 (15:10 -0400)
We can use the read-only property, together with the
accessible role, to determine whether to set editable
and read-only states for at-spi. This lets us avoid
directly poking at the widgets.

gtk/a11y/gtkatspicontext.c

index 332c52c4d7c153efe68c36729936d6a8d3e90390..2b6b3394b407c0702432f9b3a7e0aae52d8e59f7 100644 (file)
@@ -97,19 +97,23 @@ collect_states (GtkAtSpiContext    *self,
                 GVariantBuilder *builder)
 {
   GtkATContext *ctx = GTK_AT_CONTEXT (self);
-  GtkWidget *widget = GTK_WIDGET (gtk_at_context_get_accessible (ctx));
   GtkAccessibleValue *value;
   guint64 state = 0;
 
   state |= (G_GUINT64_CONSTANT (1) << ATSPI_STATE_VISIBLE);
 
-  if (GTK_IS_EDITABLE (widget) &&
-      gtk_editable_get_editable (GTK_EDITABLE (widget)))
+  if (ctx->accessible_role == GTK_ACCESSIBLE_ROLE_TEXT_BOX)
     state |= (G_GUINT64_CONSTANT (1) << ATSPI_STATE_EDITABLE);
 
-  if (GTK_IS_TEXT_VIEW (widget) &&
-      gtk_text_view_get_editable (GTK_TEXT_VIEW (widget)))
-    state |= (G_GUINT64_CONSTANT (1) << ATSPI_STATE_EDITABLE);
+  if (gtk_at_context_has_accessible_property (ctx, GTK_ACCESSIBLE_PROPERTY_READ_ONLY))
+    {
+      value = gtk_at_context_get_accessible_property (ctx, GTK_ACCESSIBLE_PROPERTY_READ_ONLY);
+      if (gtk_boolean_accessible_value_get (value))
+        {
+          state |= (G_GUINT64_CONSTANT (1) << ATSPI_STATE_READ_ONLY);
+          state &= ~(G_GUINT64_CONSTANT (1) << ATSPI_STATE_EDITABLE);
+        }
+    }
 
   if (gtk_at_context_has_accessible_state (ctx, GTK_ACCESSIBLE_STATE_BUSY))
     {